package com.hopu.oa.dao.address;

import com.hopu.oa.entity.address.Director;
import com.hopu.oa.entity.address.DirectorUsers;
import com.hopu.oa.entity.process.AoaAttachmentList;
import com.hopu.oa.entity.user.AoaUser;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface AddressDao {

    List<AoaUser> selectUserByAll(@Param("userName") String userName, @Param("alph") String alph, int index, int size);

    AoaUser findOne(int userId);

    @Select("select * from aoa_director")
    List<Director> selectDiscussnum();

    @Select("select * from aoa_director where director_id=#{uid}")
    Director selectDirectorById(int uid);

    @Select("select distinct catelog_name from aoa_director_users where user_id =#{uid} and catelog_name !=''")
    List<String> selectById(int uid);

    List<Director> selectOutById(int uid, String userName, String alph, String outtype, int index, int size);

    int addDirector(Director director);

    //附件
    int inertAttachment(AoaAttachmentList attachment);

    @Insert("insert into aoa_director_users (catelog_name,is_handle,director_id,user_id) values (#{catelogName},#{ishandle},#{directorId},#{userId})")
    int adddirectorUsers(String catelogName, int ishandle, int directorId, int userId);

    @Select("select * from aoa_director where user_name=#{name}")
    Director selectByName(String name);

    /**
     * 添加分类
     */
    @Insert("insert into aoa_director_users (catelog_name,user_id) values (#{catelogName},#{userId})")
    int addTypeName(String catelogName, int userId);

    @Select("select * from aoa_director_users where catelog_name=#{name}")
    DirectorUsers selectBYtypename(String name);

    /**
     * 删除分类
     */
    @Update("update aoa_director_users set catelog_name='' WHERE catelog_name=#{typeName}")
    int updateTypename(String typeName);

    /**
     * 查询外部个人
     */
    Director selectByDid(int uid, int did);


    /**
     * 修改
     */
    @Update("update aoa_director set address=#{address},company_number=#{companyNumber},email=#{email},image_path=#{imagePath},phone_number=#{phoneNumber},pinyin=#{pinyin},remark=#{remark},sex=#{sex},user_name=#{userName},user_id=#{userId},companyname=#{companyname} where director_id=#{directorId}")
    int updateDirectorById(Director director);

    @Update("update aoa_director_users set catelog_name=#{catelogName} where director_id=#{did} and user_id=#{uid}")
    int updateDirectorUsersById(String catelogName, int did, int uid);

    @Update("update aoa_director_users set catelog_name=#{catelogName} where user_id=#{uid} and catelog_name=#{oldtypename}")
    int updateDirectorUsersqById(String catelogName, int uid, String oldtypename);

    /**
     * 删除查询id
     */
    @Select("select director_id from aoa_director_users where director_users_id =#{id} and user_id=#{uid}")
    int selectDirectorIdByUid(int id, int uid);

    @Delete("delete from aoa_director_users where director_users_id=#{id}")
    int deletedirectorusersByDid(int id);

    @Delete("delete from aoa_director where director_id=#{did}")
    int deletedirectorByDid(int id);

    @Delete("delete from aoa_attachment_list where attachment_id=#{id}")
    int deleteattachmentByDid(int id);

    /**
     * 共享联系人
     */

    List<DirectorUsers> getMeShareMess(@Param("userId") int userId, @Param("baseKey") String baseKey, @Param("index") int index, @Param("size") int size);

    List<Director> getShareMeMess(int userId, String text, int index, int size);

    @Select("select *from aoa_director_users where director_id =#{did} and user_id =#{uid}")
    DirectorUsers selectShareMess(int did, int uid);

    @Insert("insert into aoa_director_users (is_handle,director_id,user_id,share_user_id,sharetime) values (#{ishandle},#{did},#{uid},#{sid},#{sharetime})")
    int insertShareMess(int ishandle, int did, int uid, int sid, String sharetime);

    @Update("update aoa_director_users set catelog_name=#{name},is_handle=1 where director_users_id=#{id}")
    int update(String name, int id);

    @Select("select *from aoa_director_users u where u.user_id=#{id} and u.is_handle=0 and director_id!='' and share_user_id!=''")
    List<DirectorUsers> selectByY(int id);


}
